package com.dstz.bpm.engine.model;

import cn.hutool.core.date.DateUtil;
import com.dstz.base.core.util.StringUtil;
import com.dstz.bpm.api.model.def.BpmVariableDef;

public class DefaultBpmVariableDef implements BpmVariableDef {
   private String nodeId = "";
   private String name = "";
   private String key = "";
   private String bs = "string";
   private Object bt = "";
   private boolean isRequired = false;
   private String description = "";

   public static Object getValue(String dataType, String value) {
      if ("double".equals(dataType)) {
         return new Double(value);
      } else if ("float".equals(dataType)) {
         return new Float(value);
      } else if ("int".equals(dataType)) {
         return value != null && !StringUtil.isEmpty(value) ? new Integer(value) : 0;
      } else {
         return "date".equals(dataType) ? DateUtil.parse(value) : value;
      }
   }

   public String getName() {
      return this.name;
   }

   public void setName(String name) {
      this.name = name;
   }

   public String getKey() {
      return this.key;
   }

   public void setKey(String varKey) {
      this.key = varKey;
   }

   public String getDataType() {
      return this.bs;
   }

   public void setDataType(String dataType) {
      this.bs = dataType;
   }

   public Object getDefaultVal() {
      return this.bt;
   }

   public void setDefaultVal(Object defaultVal) {
      this.bt = defaultVal;
   }

   public void setDefaultVal(String defaulVal2) {
      this.bt = getValue(this.bs, defaulVal2);
   }

   public boolean getIsRequired() {
      return this.isRequired;
   }

   public void setIsRequired(boolean isRequired) {
      this.isRequired = isRequired;
   }

   public boolean isRequired() {
      return this.isRequired;
   }

   public void setRequired(boolean isRequired) {
      this.isRequired = isRequired;
   }

   public String getDescription() {
      return this.description == null ? "" : this.description;
   }

   public void setDescription(String description) {
      this.description = description;
   }

   public String getNodeId() {
      return this.nodeId;
   }

   public void setNodeId(String nodeId) {
      this.nodeId = nodeId;
   }
}
